package com.dragonsen.log.helper;


import com.dragonsen.log.LogConfig;

import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class CheckVisitor extends MethodVisitor {

    private final String owner;

    CheckVisitor(MethodVisitor mv, String owner) {
        super(Opcodes.ASM5, mv);
        this.owner = owner;
    }

//    ALOAD 0
//    GETFIELD com/example/reagent_management/ui/setting/TestFragment$initViewOrObserve$$inlined$with$lambda$2.this$0 : Lcom/example/reagent_management/ui/setting/TestFragment;
//    INVOKESTATIC com/example/reagent_management/ui/setting/TestFragment.access$getLog$p (Lcom/example/reagent_management/ui/setting/TestFragment;)Lcom/example/reagent_management/ui/setting/LogUtils;
//    LDC "222"
//    INVOKEVIRTUAL com/example/reagent_management/ui/setting/LogUtils.log (Ljava/lang/String;)V

    //
    //插入想插入的方法
    @Override
    public void visitCode() {
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, owner, "log",
                String.format("L%s;", LogConfig.ByteCodeInjectClassName));
        mv.visitLdcInsn("11111");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,"com/example/reagent_management/ui/setting/LogUtils","log","(Ljava/lang/String;)V", false);
//        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "android/view/View", "getId", "()I", false);
//        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/String", "valueOf", "(I)Ljava/lang/String;", false);
//        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/example/reagent_management/ui/setting/LogUtils", "log", "(Ljava/lang/String;)V", false);

//        super.visitCode();
    }
}
